package com.qidian.buy.goods.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qidian.buy.common.pojo.BuyResult;
import com.qidian.buy.pojo.ItemSpecification;
import com.qidian.buy.goods.mapper.ItemSpecificationMapper;
import com.qidian.buy.goods.service.IItemSpecificationService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 戴着假发的程序员
 * @since 2024-07-17 09:36:01
 */
@Service
public class ItemSpecificationServiceImpl extends ServiceImpl<ItemSpecificationMapper, ItemSpecification> implements IItemSpecificationService {
    @Autowired
    private ItemSpecificationMapper speMapper;
    @Override
    public BuyResult queryList(int pageNum, int limit, ItemSpecification spe) {
        QueryWrapper<ItemSpecification> wrapper = new QueryWrapper<>();
        if(spe != null) {
            wrapper.eq(spe.getStatus()!= null && !spe.getStatus().equals(new Integer(0)),"status",spe.getStatus())
                    .like(spe.getSpeName() != null && !spe.getSpeName().equals(""),"spe_name",spe.getSpeName());
        }
        IPage<ItemSpecification> page = new Page<>(pageNum,limit);
        return BuyResult.success(speMapper.selectPage(page,wrapper));
    }

    @Override
    public BuyResult saveSpe(ItemSpecification spe) {
        return BuyResult.isSuccess(speMapper.insert(spe));
    }

    @Override
    public BuyResult get(Long speId) {
        return BuyResult.success(speMapper.selectById(speId));
    }
}
